﻿using Google.Protobuf.WellKnownTypes;
using NPOI.HPSF;
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
using System.Windows.Threading;
using CosAging.View;

namespace CosAging
{
    public class SimpleBinding : INotifyPropertyChanged

    {

        string _BindingName;
        public string BindingName
        {
            get
            {
                return _BindingName;
            }
            set
            {
                _BindingName = value;
                NotifyPropertyChanged("BindingName");
            }
        }

        string _stringvalue;
        public string stringvalue
        {
            get
            {
                return _stringvalue;
            }
            set
            {
                _stringvalue = value;
                NotifyPropertyChanged("stringvalue");
            }
        }

        int _intvalue;
        public int intvalue
        {
            get
            {
                return _intvalue;
            }
            set
            {
                _intvalue = value;
                NotifyPropertyChanged("intvalue");
            }
        }

        float _floatvalue;
        public float floatvalue
        {
            get
            {
                return _floatvalue;
            }
            set
            {
                _floatvalue = value;
                NotifyPropertyChanged("floatvalue");
            }
        }

        string _beijingtime;
        public string beijingtime
        {
            get
            {
                return _beijingtime;
            }
            set
            {
                _beijingtime = value;
                NotifyPropertyChanged("beijingtime");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    public class ComboBoxBinding : INotifyPropertyChanged
    {
        int _Local_ID;
        public int Local_ID
        {
            get
            {
                return _Local_ID;
            }
            set
            {
                _Local_ID = value;
                NotifyPropertyChanged(nameof(Local_ID));
            }
        }


        string _测试项;
        public string 测试项
        {
            get
            {
                return _测试项;
            }
            set
            {
                _测试项 = value;
                NotifyPropertyChanged(nameof(测试项));
            }
        }

        int _功率百分比;
        public int 功率百分比
        {
            get
            {
                return _功率百分比;
            }
            set
            {
                _功率百分比 = value;
                NotifyPropertyChanged(nameof(功率百分比));
            }
        }

        int _调制频率;
        public int 调制频率
        {
            get
            {
                return _调制频率;
            }
            set
            {
                _调制频率 = value;
                NotifyPropertyChanged(nameof(调制频率));
            }
        }

        string _调制频率单位;
        public string 调制频率单位
        {
            get
            {
                _调制频率单位 = "(" + 调制频率下限.ToString() + "-" + 调制频率上限.ToString() + ")" + 频率单位;
                return _调制频率单位;
            }
            set
            {
                _调制频率单位 = value;
                NotifyPropertyChanged(nameof(调制频率单位));
            }
        }

        string _频率单位;
        public string 频率单位
        {
            get
            {
                return _频率单位;
            }
            set
            {
                _频率单位 = value;
                NotifyPropertyChanged(nameof(频率单位));
            }
        }

        int _调制频率下限;
        public int 调制频率下限
        {
            get
            {
                return _调制频率下限;
            }
            set
            {
                _调制频率下限 = value;
                NotifyPropertyChanged(nameof(调制频率下限));
            }
        }

        int _调制频率上限;
        public int 调制频率上限
        {
            get
            {
                return _调制频率上限;
            }
            set
            {
                _调制频率上限 = value;
                NotifyPropertyChanged(nameof(调制频率上限));
            }
        }



        int _占空比;
        public int 占空比
        {
            get
            {
                return _占空比;
            }
            set
            {
                _占空比 = value;
                NotifyPropertyChanged(nameof(占空比));
            }
        }

        int _测试时间;
        public int 测试时间
        {
            get
            {
                return _测试时间;
            }
            set
            {
                _测试时间 = value;
                NotifyPropertyChanged(nameof(测试时间));
            }
        }

        string _测试时间单位;
        public string 测试时间单位
        {
            get
            {
                _测试时间单位 = "(" + 测试时间下限.ToString() + "-" + 测试时间上限.ToString() + ")" + 测试单位;
                return _测试时间单位;
            }
            set
            {
                _测试时间单位 = value;
                NotifyPropertyChanged(nameof(测试时间单位));
            }
        }

        string _测试单位;
        public string 测试单位
        {
            get
            {
                return _测试单位;
            }
            set
            {
                _测试单位 = value;
                NotifyPropertyChanged(nameof(测试单位));
            }
        }

        int _测试时间下限;
        public int 测试时间下限
        {
            get
            {
                return _测试时间下限;
            }
            set
            {
                _测试时间下限 = value;
                NotifyPropertyChanged(nameof(测试时间下限));
            }
        }

        int _测试时间上限;
        public int 测试时间上限
        {
            get
            {
                return _测试时间上限;
            }
            set
            {
                _测试时间上限 = value;
                NotifyPropertyChanged(nameof(测试时间上限));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    public class CommandDictionary : INotifyPropertyChanged

    {


        public int ID { get; set; }


        public string CommandName { get; set; }


        public string CommandClass { get; set; }


        public string CanRead { get; set; }


        public string CommandStep { get; set; }


        public string ReturnFormat { get; set; }

        public string Target { get; set; }


        public IPEndPoint TargetIP { get; set; }


        public int TimeDelay { get; set; }


        public bool HasRev { get; set; }


        public bool HasSend { get; set; }


        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    public class CosBinding : INotifyPropertyChanged

    {
        int _选通通道号;
        public int 选通通道号
        {
            get
            {
                return _选通通道号;
            }
            set
            {
                _选通通道号 = value;
                NotifyPropertyChanged(nameof(选通通道号));
            }
        }
        int _通道起;
        public int 通道起
        {
            get
            {
                return _通道起;
            }
            set
            {
                _通道起 = value;
                NotifyPropertyChanged(nameof(通道起));
            }
        }
        int _通道止;
        public int 通道止
        {
            get
            {
                return _通道止;
            }
            set
            {
                _通道止 = value;
                NotifyPropertyChanged(nameof(通道止));
            }
        }
        string _物料编码;
        public string 物料编码
        {
            get
            {
                return _物料编码;
            }
            set
            {
                _物料编码 = value;
                NotifyPropertyChanged(nameof(物料编码));
            }
        }

        string _产品批号;
        public string 产品批号
        {
            get
            {
                return _产品批号;
            }
            set
            {
                _产品批号 = value;
                NotifyPropertyChanged(nameof(产品批号));
            }
        }

        string _产品型号;
        public string 产品型号
        {
            get
            {
                return _产品型号;
            }
            set
            {
                _产品型号 = value;
                NotifyPropertyChanged(nameof(产品型号));
            }
        }

        string _单元报警温度;
        public string 单元报警温度
        {
            get
            {
                return _单元报警温度;
            }
            set
            {
                _单元报警温度 = value;
                NotifyPropertyChanged(nameof(单元报警温度));
            }
        }

        string _水冷报警温度;
        public string 水冷报警温度
        {
            get
            {
                return _水冷报警温度;
            }
            set
            {
                _水冷报警温度 = value;
                NotifyPropertyChanged(nameof(水冷报警温度));
            }
        }

        string _一阶段电流;
        public string 一阶段电流
        {
            get
            {
                return _一阶段电流;
            }
            set
            {
                _一阶段电流 = value;
                NotifyPropertyChanged(nameof(一阶段电流));
            }
        }
        string _一阶段时间;
        public string 一阶段时间
        {
            get
            {
                return _一阶段时间;
            }
            set
            {
                _一阶段时间 = value;
                NotifyPropertyChanged(nameof(一阶段时间));
            }
        }
        string _二阶段电流;
        public string 二阶段电流
        {
            get
            {
                return _二阶段电流;
            }
            set
            {
                _二阶段电流 = value;
                NotifyPropertyChanged(nameof(二阶段电流));
            }
        }
        string _二阶段时间;
        public string 二阶段时间
        {
            get
            {
                return _二阶段时间;
            }
            set
            {
                _二阶段时间 = value;
                NotifyPropertyChanged(nameof(二阶段时间));
            }
        }
        string _三阶段电流;
        public string 三阶段电流
        {
            get
            {
                return _三阶段电流;
            }
            set
            {
                _三阶段电流 = value;
                NotifyPropertyChanged(nameof(三阶段电流));
            }
        }
        string _三阶段时间;
        public string 三阶段时间
        {
            get
            {
                return _三阶段时间;
            }
            set
            {
                _三阶段时间 = value;
                NotifyPropertyChanged(nameof(三阶段时间));
            }
        }
        string _脉冲老化电流;
        public string 脉冲老化电流
        {
            get
            {
                return _脉冲老化电流;
            }
            set
            {
                _脉冲老化电流 = value;
                NotifyPropertyChanged(nameof(脉冲老化电流));
            }
        }
        string _脉冲老化时间;
        public string 脉冲老化时间
        {
            get
            {
                return _脉冲老化时间;
            }
            set
            {
                _脉冲老化时间 = value;
                NotifyPropertyChanged(nameof(脉冲老化时间));
            }
        }
        string _频率;
        public string 频率
        {
            get
            {
                return _频率;
            }
            set
            {
                _频率 = value;
                NotifyPropertyChanged(nameof(频率));
            }
        }
        string _占空比;
        public string 占空比
        {
            get
            {
                return _占空比;
            }
            set
            {
                _占空比 = value;
                NotifyPropertyChanged(nameof(占空比));
            }
        }
        string _结束时间;
        public string 结束时间
        {
            get
            {
                return _结束时间;
            }
            set
            {
                _结束时间 = value;
                NotifyPropertyChanged(nameof(结束时间));
            }
        }
        string _倒计时;
        public string 倒计时
        {
            get
            {
                return _倒计时;
            }
            set
            {
                _倒计时 = value;
                NotifyPropertyChanged(nameof(倒计时));
            }
        }
        private CBlist _selectLocation;
        public CBlist SelectLocation
        {
            get
            {
                return this._selectLocation;
            }
            set
            {
                this._selectLocation = value;
                if (this.PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("SelectLocation"));
            }
        }
        private ObservableCollection<CBlist> _locationRoad = null;
        public ObservableCollection<CBlist> LocationSource
        {
            get
            {
                if (this._locationRoad == null)
                {
                    this._locationRoad = new ObservableCollection<CBlist> {
                 new CBlist() { ID = 0, Name = "连续模式", Value = 0 },
                 new CBlist() { ID = 1, Name = "脉冲模式", Value = 1 },
                 };

                }
                return this._locationRoad;
            }
            set
            {
                this._locationRoad = value;
                if (this.PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("LocationSource"));
            }
        }
        public ConcurrentDictionary<int, 测试单元格> CD测试单元格 { get; set; }
        bool _enable;
        public bool enable
        {
            get
            {
                return _enable;
            }
            set
            {
                _enable = value;
                NotifyPropertyChanged("enable");
            }
        }
        //===================================================

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    public class 设置参数 : INotifyPropertyChanged
    {
        public bool 临时阶梯加电状态 { get; set; }

        string _阶段停留时长1;
        public string 阶段停留时长1
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长1;
            }
            set
            {
                _阶段停留时长1 = value;
                NotifyPropertyChanged(nameof(阶段停留时长1));
            }
        }

        string _阶段停留时长2;
        public string 阶段停留时长2
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长2;
            }
            set
            {
                _阶段停留时长2 = value;
                NotifyPropertyChanged(nameof(阶段停留时长2));
            }
        }

        string _阶段停留时长3;
        public string 阶段停留时长3
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长3;
            }
            set
            {
                _阶段停留时长3 = value;
                NotifyPropertyChanged(nameof(阶段停留时长3));
            }
        }

        string _阶段停留时长4;
        public string 阶段停留时长4
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长4;
            }
            set
            {
                _阶段停留时长4 = value;
                NotifyPropertyChanged(nameof(阶段停留时长4));
            }
        }

        string _阶段停留时长5;
        public string 阶段停留时长5
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长5;
            }
            set
            {
                _阶段停留时长5 = value;
                NotifyPropertyChanged(nameof(阶段停留时长5));
            }
        }

        string _阶段停留时长6;
        public string 阶段停留时长6
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长6;
            }
            set
            {
                _阶段停留时长6 = value;
                NotifyPropertyChanged(nameof(阶段停留时长6));
            }
        }

        string _阶段停留时长7;
        public string 阶段停留时长7
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长7;
            }
            set
            {
                _阶段停留时长7 = value;
                NotifyPropertyChanged(nameof(阶段停留时长7));
            }
        }

        string _阶段停留时长8;
        public string 阶段停留时长8
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长8;
            }
            set
            {
                _阶段停留时长8 = value;
                NotifyPropertyChanged(nameof(阶段停留时长8));
            }
        }

        string _阶段停留时长9;
        public string 阶段停留时长9
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长9;
            }
            set
            {
                _阶段停留时长9 = value;
                NotifyPropertyChanged(nameof(阶段停留时长9));
            }
        }

        string _阶段停留时长10;
        public string 阶段停留时长10
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段停留时长10;
            }
            set
            {
                _阶段停留时长10 = value;
                NotifyPropertyChanged(nameof(阶段停留时长10));
            }
        }

        string _阶段电流1;
        public string 阶段电流1
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流1;
            }
            set
            {
                _阶段电流1 = value;
                NotifyPropertyChanged(nameof(阶段电流1));
            }
        }

        string _阶段电流2;
        public string 阶段电流2
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流2;
            }
            set
            {
                _阶段电流2 = value;
                NotifyPropertyChanged(nameof(阶段电流2));
            }
        }

        string _阶段电流3;
        public string 阶段电流3
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流3;
            }
            set
            {
                _阶段电流3 = value;
                NotifyPropertyChanged(nameof(阶段电流3));
            }
        }

        string _阶段电流4;
        public string 阶段电流4
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流4;
            }
            set
            {
                _阶段电流4 = value;
                NotifyPropertyChanged(nameof(阶段电流4));
            }
        }

        string _阶段电流5;
        public string 阶段电流5
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流5;
            }
            set
            {
                _阶段电流5 = value;
                NotifyPropertyChanged(nameof(阶段电流5));
            }
        }

        string _阶段电流6;
        public string 阶段电流6
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流6;
            }
            set
            {
                _阶段电流6 = value;
                NotifyPropertyChanged(nameof(阶段电流6));
            }
        }

        string _阶段电流7;
        public string 阶段电流7
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流7;
            }
            set
            {
                _阶段电流7 = value;
                NotifyPropertyChanged(nameof(阶段电流7));
            }
        }

        string _阶段电流8;
        public string 阶段电流8
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流8;
            }
            set
            {
                _阶段电流8 = value;
                NotifyPropertyChanged(nameof(阶段电流8));
            }
        }

        string _阶段电流9;
        public string 阶段电流9
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流9;
            }
            set
            {
                _阶段电流9 = value;
                NotifyPropertyChanged(nameof(阶段电流9));
            }
        }

        string _阶段电流10;
        public string 阶段电流10
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _阶段电流10;
            }
            set
            {
                _阶段电流10 = value;
                NotifyPropertyChanged(nameof(阶段电流10));
            }
        }

        string _有效阶段数;
        public string 有效阶段数
        {
            get
            {
                //_阶段停留时长1 = 阶段停留时长1;
                return _有效阶段数;
            }
            set
            {
                _有效阶段数 = value;
                NotifyPropertyChanged(nameof(有效阶段数));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    public class 测试单元格 : INotifyPropertyChanged
    {
        public int 通道号   {  get; set; }
        public string 物料编码 { get; set; }
        public string 产品批号 { get; set; }
        public string 产品型号 { get; set; }
        public double 单元报警温度 { get; set; }
        //==========================================
        string _故障说明;
        public string 故障说明
        {
            get
            {
                _故障说明 = PublicClass.故障代码对应表[故障代码];
                return _故障说明;
            }
            set
            {
                _故障说明 = value;
                NotifyPropertyChanged(nameof(故障说明));
            }
        }

        int _故障代码;
        public int 故障代码
        {
            get
            {
                return _故障代码;
            }
            set
            {
                _故障代码 = value;
                NotifyPropertyChanged(nameof(故障代码));
                NotifyPropertyChanged(nameof(故障说明));
            }
        }
        //==========================================
        string _电流;
        public string 电流
        {
            get
            {
                _电流 = double电流.ToString("F1");
                return _电流;
            }
            set
            {
                _电流 = value;
                NotifyPropertyChanged(nameof(电流));
            }
        }

        double _double电流;
        public double double电流
        {
            get
            {
                return _double电流;
            }
            set
            {
                _double电流 = value;
                NotifyPropertyChanged(nameof(double电流));
                NotifyPropertyChanged(nameof(电流));
            }
        }
        //==========================================
        string _结束时间;
        public string 结束时间
        {
            get
            {   
                return _结束时间;
            }
            set
            {
                _结束时间 = value;
                NotifyPropertyChanged(nameof(结束时间));
            }
        }

        DateTime _DT结束时间;
        public DateTime DT结束时间
        {
            get
            {
                return _DT结束时间;
            }
            set
            {
                _DT结束时间 = value;
                NotifyPropertyChanged(nameof(DT结束时间));
            }
        }

        string _开始时间;
        public string 开始时间
        {
            get
            {
                //_开始时间 = DT开始时间.ToString("yyyy/MM/dd HH:mm:ss");
                return _开始时间;
            }
            set
            {
                _开始时间 = value;
                NotifyPropertyChanged(nameof(开始时间));
            }
        }

        DateTime _DT开始时间;
        public DateTime DT开始时间
        {
            get
            {
                return _DT开始时间;
            }
            set
            {
                _DT开始时间 = value;
                NotifyPropertyChanged(nameof(DT开始时间));
            }
        }
        //==========================================
        int _通道状态; //0空闲1工作2报警4通信失败
        public int 通道状态
        {
            get
            {

                return _通道状态;
            }
            set
            {
                _通道状态 = value;
                NotifyPropertyChanged(nameof(通道状态));
                NotifyPropertyChanged(nameof(通道背景色));
                NotifyPropertyChanged(nameof(str通道状态));
            }
        }

        DateTime _DT发送时间;
        public DateTime DT发送时间
        {
            get
            {
                return _DT发送时间;
            }
            set
            {
                _DT发送时间 = value;
                NotifyPropertyChanged(nameof(DT发送时间));
            }
        }
        DateTime _DT收到时间;
        public DateTime DT收到时间
        {
            get
            {
                return _DT收到时间;
            }
            set
            {
                _DT收到时间 = value;
                NotifyPropertyChanged(nameof(DT收到时间));
            }
        }
        string _str通道状态; 
        public string str通道状态
        {
            get
            {
                if (通道状态 == 0)
                {
                    _str通道状态 = "空闲";
                }
                else if (通道状态 == 1)
                {
                    _str通道状态 = "正在老化";
                }
                else if (通道状态 == 2)
                {
                    _str通道状态 = 故障说明;
                }
                else
                {
                    _str通道状态 = "未连接";
                }
                return _str通道状态;
            }
            set
            {
                _str通道状态 = value;
                NotifyPropertyChanged(nameof(str通道状态));
            }
        }

        Brush _通道背景色;
        public Brush 通道背景色
        {
            get
            {
                if (通道状态==0)
                {
                    _通道背景色 = new SolidColorBrush(Colors.Transparent);
                }
                else if (通道状态 == 1)
                {
                    _通道背景色 = new SolidColorBrush(Colors.Green);
                }
                else if (通道状态 == 2)
                {
                    _通道背景色 = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    _通道背景色 = new SolidColorBrush(Colors.CornflowerBlue);
                }
                return _通道背景色;
            }
            set
            {
                _通道背景色 = value;
                NotifyPropertyChanged(nameof(通道背景色));
            }
        }

        bool _是否被选中; //0空闲1工作2报警4通信失败
        public bool 是否被选中
        {
            get
            {

                return _是否被选中;
            }
            set
            {
                _是否被选中 = value;
                NotifyPropertyChanged(nameof(是否被选中));
            }
        }

        //==========================================
        public ConcurrentDictionary<int, 测试芯片> CD测试芯片 { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    public class 测试芯片 : INotifyPropertyChanged
    {

        string _温度;
        public string 温度
        {
            get
            {
                _温度 = double温度.ToString("F1");
                return _温度;
            }
            set
            {
                _温度 = value;
                NotifyPropertyChanged(nameof(温度));
            }
        }

        double _double温度;
        public double double温度
        {
            get
            {
                return _double温度;
            }
            set
            {
                _double温度 = value;
                NotifyPropertyChanged(nameof(double温度));
                NotifyPropertyChanged(nameof(温度));
            }
        }
        //==========================================
        string _功率;
        public string 功率
        {
            get
            {
                _功率 = double功率.ToString("F0");
                return _功率;
            }
            set
            {
                _功率 = value;
                NotifyPropertyChanged(nameof(功率));
            }
        }

        double _double功率;
        public double double功率
        {
            get
            {
                return _double功率;
            }
            set
            {
                _double功率 = value;
                NotifyPropertyChanged(nameof(double功率));
                NotifyPropertyChanged(nameof(功率));
            }
        }
      
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    public class workingdata : INotifyPropertyChanged
    {

        string _batchnumber;
        public string batchnumber
        {
            get
            {
                return _batchnumber;
            }
            set
            {
                _batchnumber = value;
                NotifyPropertyChanged("batchnumber");
            }
        }
        string _model;
        public string model
        {
            get
            {
                return _model;
            }
            set
            {
                _model = value;
                NotifyPropertyChanged("model");
            }
        }
        string _agingcurrent;
        public string agingcurrent
        {
            get
            {
                return _agingcurrent;
            }
            set
            {
                _agingcurrent = value;
                NotifyPropertyChanged("agingcurrent");
            }
        }
        string _agingtime;
        public string agingtime
        {
            get
            {
                return _agingtime;
            }
            set
            {
                _agingtime = value;
                NotifyPropertyChanged("agingtime");
            }
        }
        string _agingunit;
        public string agingunit
        {
            get
            {
                return _agingunit;
            }
            set
            {
                _agingunit = value;
                NotifyPropertyChanged("agingunit");
            }
        }
        string _endtime;
        public string endtime
        {
            get
            {
                return _endtime;
            }
            set
            {
                _endtime = value;
                NotifyPropertyChanged("endtime");
            }
        }
        string _begintime;
        public string begintime
        {
            get
            {
                return _begintime;
            }
            set
            {
                _begintime = value;
                NotifyPropertyChanged("begintime");
            }
        }
        string _stoptime;
        public string stoptime
        {
            get
            {
                return _stoptime;
            }
            set
            {
                _stoptime = value;
                NotifyPropertyChanged("stoptime");
            }
        }

        
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }  
    public class operationrecords : INotifyPropertyChanged
    {

        string _operatetime;
        public string operatetime
        {
            get
            {
                return _operatetime;
            }
            set
            {
                _operatetime = value;
                NotifyPropertyChanged("operatetime");
            }
        }
        string _operatecontent;
        public string operatecontent
        {
            get
            {
                return _operatecontent;
            }
            set
            {
                _operatecontent = value;
                NotifyPropertyChanged("operatecontent");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    public class PublicClass
    {
        [DllImport("kernel32")]
        public static extern int QueryPerformanceFrequency(ref long x);
        [DllImport("kernel32")]
        public static extern int QueryPerformanceCounter(ref long x);
        //=====================测试计时======================
        public static double 时间差;
        public static long start_Value = 0;
        public static long freq = 0;
        public static long stop_Value = 0;
        public static List<double> CanvasListValue = new List<double>() { 0.0, 0.0, 0.0, 0.0, 0.0 };
        public static Dictionary<int, string> 故障代码对应表 = new Dictionary<int, string>();
        public static string Apppath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; //获取启动了应用程序的可执行文件的路径，不包括可执行文件的名称
        public static bool keyboardsShow = false;
        public static keyboards kb = new keyboards();
        public static int AppCloseStep = 0;
        public static int selectX; public static int selectY;
        public static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
        public static IWorkbook SDTIBook = null;
        public static string filePathSDT = Apppath + "txt\\" + "SDT.xls";
        public static DataTable myDataTable1 = new DataTable();

        public static IWorkbook ComboBoxIBook = null;
        public static string filePathComboBox = PublicClass.Apppath + "txt\\" + "ComboBox.xls";
        public static DataTable myDataTable2 = new DataTable();

        public static ConcurrentDictionary<int, ComboBoxBinding> CDComboBox = new ConcurrentDictionary<int, ComboBoxBinding>();

        public static IWorkbook CommandIBook = null;
        public static string filePathCommand = PublicClass.Apppath + "txt\\" + "Command.xls";
        public static DataTable myDataTable3 = new DataTable();

        public static ConcurrentDictionary<int, CommandDictionary> CDCommand = new ConcurrentDictionary<int, CommandDictionary>();

        public static IWorkbook UploadParametersIBook = null;
        public static string filePathUploadParameters = PublicClass.Apppath + "txt\\" + "UploadParameters.xls";
        public static DataTable myDataTable4 = new DataTable();

        public static IWorkbook BWT001IBook = null;
        public static string filePathBWT001 = PublicClass.Apppath + "txt\\" + "BWT001.xls";
        public static DataTable myDataTable5 = new DataTable();

        public static SimpleBinding Loginstate = new SimpleBinding();
        public static CosBinding CosBobject= new CosBinding();
        public static iniFileWR myIniFile = new iniFileWR();
        public static string INISYS = "sys.ini";
        public static void 计时起点() //返回起始点数值
        {
            QueryPerformanceFrequency(ref freq);
            QueryPerformanceCounter(ref start_Value);
        }

        public static void 计时终点()//计算与起始点的差值返回毫秒单位的时间差
        {
            QueryPerformanceCounter(ref stop_Value);
            时间差 = (double)(stop_Value - start_Value) / (double)(freq) * 1000;
        }
        public static System.Windows.Media.Color ToColor(string colorName)
        {
            if (colorName.StartsWith("#"))
            {
                colorName = colorName.Replace("#", string.Empty);

                byte A, R, G, B;
                string hexadecimal;

                hexadecimal = (colorName.Substring(0, 2));
                A = Convert.ToByte(hexadecimal, 16);
                hexadecimal = (colorName.Substring(2, 2));
                R = Convert.ToByte(hexadecimal, 16);
                hexadecimal = (colorName.Substring(4, 2));
                G = Convert.ToByte(hexadecimal, 16);
                hexadecimal = (colorName.Substring(6, 2));
                B = Convert.ToByte(hexadecimal, 16);
                return System.Windows.Media.Color.FromArgb(A, R, G, B);
            }
            else
            {
                return System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
            }
        }

        public static string ConvertString(string value, int fromBase, int toBase)
        {
            int n = Convert.ToInt32(value, fromBase);
            return Convert.ToString(n, toBase);
        }
        public static double RD2(double value)
        {
            double f1 = Convert.ToDouble(Math.Round(Convert.ToDecimal(value), 2, MidpointRounding.AwayFromZero).ToString());
            return f1;
        }
        public static double RD3(double value)
        {
            double f1 = Convert.ToDouble(Math.Round(Convert.ToDecimal(value), 3, MidpointRounding.AwayFromZero).ToString());
            return f1;
        }
        public static DateTime ChinaAreaTime(DateTime DT)
        {
            DateTime chinaDT = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DT, "China Standard Time"); //中国标准时间
            return chinaDT;
        }
        public static void KeyboardandShutdown(object sender, KeyEventArgs e)
        {
            if (e.KeyStates == Keyboard.GetKeyStates(Key.LeftCtrl) & keyboardsShow == false)
            {

                //keyboardsShow = true;
                Process Process = new System.Diagnostics.Process();
                Process.Start(AccessDB.Apppath + "keyboard\\keyboard.exe");

                //kb.Show();
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.LeftCtrl) & keyboardsShow == true)
            {

                //keyboardsShow = false;
                //kb.Hide();
            }

            if (e.KeyStates == Keyboard.GetKeyStates(Key.Up) & AppCloseStep == 0)
            {
                AppCloseStep = 1;
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.Up) & AppCloseStep == 1)
            {
                AppCloseStep = 2;
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.Down) & AppCloseStep == 2)
            {
                AppCloseStep = 3;
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.Down) & AppCloseStep == 3)
            {
                AppCloseStep = 4;
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.Left) & AppCloseStep == 4)
            {
                AppCloseStep = 5;
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.Right) & AppCloseStep == 5)
            {
                AppCloseStep = 6;
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.Left) & AppCloseStep == 6)
            {
                AppCloseStep = 7;
            }
            else if (e.KeyStates == Keyboard.GetKeyStates(Key.Right) & AppCloseStep == 7)
            {
                AppCloseStep = 0;
                System.Windows.Application.Current.Shutdown();
            }
            else
            {
                AppCloseStep = 0;
            }
        }

        public static int GetWeekOfYear(DateTime dt)
        {
            GregorianCalendar gc = new GregorianCalendar();
            int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
            return weekOfYear;
        }
        /// <summary>
        /// 获取本周的周一日期
        /// </summary>
        /// <returns></returns>
        public static DateTime GetThisWeekSunday(DateTime date)
        {

            DateTime firstDate = DateTime.Now;
            switch (date.DayOfWeek)
            {
                case System.DayOfWeek.Sunday:
                    firstDate = date.AddDays(-0);
                    break;
                case System.DayOfWeek.Monday:
                    firstDate = date.AddDays(-1);
                    break;
                case System.DayOfWeek.Tuesday:
                    firstDate = date.AddDays(-2);
                    break;
                case System.DayOfWeek.Wednesday:
                    firstDate = date.AddDays(-3);
                    break;
                case System.DayOfWeek.Thursday:
                    firstDate = date.AddDays(-4);
                    break;
                case System.DayOfWeek.Friday:
                    firstDate = date.AddDays(-5);
                    break;
                case System.DayOfWeek.Saturday:
                    firstDate = date.AddDays(-6);
                    break;
            }
            return firstDate;
        }
        public static bool Readfile(string filePath, out IWorkbook IBook)
        {
            bool flag = false; IBook = null;
            //OpenFileDialog openFile = new OpenFileDialog();
            //openFile.Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls";
            //openFile.FilterIndex = 2;
            //openFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            //openFile.Multiselect = false;


            string fileType = System.IO.Path.GetExtension(filePath);
            if (string.IsNullOrEmpty(fileType))
            {
                MessageBox.Show("路径位空！");
                return flag;
            }
            FileStream fs = null;
            try
            {
                using (fs = File.OpenRead(filePath))
                {
                    // 2007版本
                    if (filePath.IndexOf(".xlsx") > 0)
                    {
                        IBook = new XSSFWorkbook(fs);
                        flag = true;
                    }
                    // 2003版本
                    else if (filePath.IndexOf(".xls") > 0)
                    {
                        IBook = new HSSFWorkbook(fs);
                        flag = true;
                    }

                    if (IBook == null)
                    {
                        MessageBox.Show("找不到文件！");
                    }
                }
            }
            catch (Exception ex)
            {
                NLOGex(ex);
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return flag;
        }
        public static DataTable ReadQueryTable(bool isColumnName, IWorkbook IBook)
        {

            bool jump = false;
            DataTable dataTable = new DataTable();
            DataColumn column = null;
            DataRow dataRow = null;

            ISheet sheet = null;
            IRow row = null;
            ICell cell = null;
            int startRow = 0;
            try
            {

                if (IBook != null)
                {
                    sheet = IBook.GetSheetAt(0);//读取第一个sheet，当然也可以循环读取每个sheet
                                                //sheet = Public.workbook.GetSheet("电机");
                                                //sheet = workbook.GetSheet("shop floor plan");
                    dataTable = new DataTable();
                    if (sheet != null)
                    {
                        int rowCount = sheet.LastRowNum;//总行数
                        if (rowCount > 0)
                        {
                            IRow firstRow = sheet.GetRow(0);//第一行
                            int cellCount = firstRow.LastCellNum;//列数

                            //构建datatable的列
                            if (isColumnName)
                            {
                                startRow = 1;//如果第一行是列名，则从第二行开始读取
                                for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
                                {
                                    cell = firstRow.GetCell(i);
                                    if (cell != null)
                                    {
                                        if (cell.StringCellValue != null)
                                        {
                                            column = new DataColumn(cell.StringCellValue);
                                            dataTable.Columns.Add(column);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
                                {
                                    column = new DataColumn("column" + (i + 1));
                                    dataTable.Columns.Add(column);
                                }
                            }

                            //填充行
                            for (int i = startRow; i <= rowCount; ++i)
                            {
                                row = sheet.GetRow(i);
                                if (row == null) continue;

                                dataRow = dataTable.NewRow();
                                for (int j = row.FirstCellNum; j < cellCount; j++)
                                {
                                    cell = row.GetCell(j);
                                    if (cell == null)
                                    {
                                        dataRow[j] = "";
                                        //jump = true;
                                    }
                                    else
                                    {
                                        //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
                                        switch (cell.CellType)
                                        {
                                            case CellType.Blank:
                                                dataRow[j] = "";
                                                break;
                                            case CellType.Numeric:
                                                short format = cell.CellStyle.DataFormat;
                                                //对时间格式（2015.12.5、2015/12/5、2015-12-5等）的处理
                                                if (format == 14 || format == 31 || format == 57 || format == 58)
                                                {
                                                    dataRow[j] = cell.DateCellValue;
                                                }

                                                else
                                                {
                                                    dataRow[j] = cell.NumericCellValue;
                                                }
                                                break;
                                            case CellType.String:
                                                dataRow[j] = cell.StringCellValue;

                                                break;
                                        }
                                        jump = false;
                                    }
                                }
                                if (jump == false) dataTable.Rows.Add(dataRow);
                            }
                        }
                    }
                }

                return dataTable;
            }
            catch (Exception ex)
            {
                NLOGex(ex);
                return null;
            }
        }


        //创建对象
        public static void CreatObject()
        {
            try
            {
                故障代码对应表.Add(0, "无报警"); 故障代码对应表.Add(1, "电流超限"); 故障代码对应表.Add(2, "电流过小"); 故障代码对应表.Add(3, "电源失控"); 
                故障代码对应表.Add(4, "控制电压"); 故障代码对应表.Add(5, "MOS功率超限"); 故障代码对应表.Add(6, "关机失败报警"); 故障代码对应表.Add(7, "温度1报警");
                故障代码对应表.Add(8, "温度2报警"); 故障代码对应表.Add(9, "温度3报警"); 故障代码对应表.Add(10, "温度4报警"); 故障代码对应表.Add(11, "温度5报警");
                故障代码对应表.Add(12, "温度6报警"); 故障代码对应表.Add(13, "温度7报警"); 故障代码对应表.Add(14, "温度8报警"); 故障代码对应表.Add(15, "温度9报警");
                故障代码对应表.Add(16, "温度10报警"); 故障代码对应表.Add(17, "温度11报警"); 故障代码对应表.Add(18, "温度12报警"); 故障代码对应表.Add(19, "短路报警");
                故障代码对应表.Add(20, "过流报警"); 故障代码对应表.Add(21, "MOS过温报警"); 故障代码对应表.Add(22, "参数写入错误"); 故障代码对应表.Add(23, "参数读取错误");
                故障代码对应表.Add(24, "电源DC故障"); 故障代码对应表.Add(25, "电源AC故障"); 故障代码对应表.Add(26, "电流失控"); 故障代码对应表.Add(27, "电流调节到最大值");
                ConcurrentDictionary<int, 测试单元格> CD测试单元格 = new ConcurrentDictionary<int, 测试单元格>();
                for (int i = 0; i <8; i++)
                {                  
                    ConcurrentDictionary<int, 测试芯片> CD测试芯片 = new ConcurrentDictionary<int, 测试芯片>();
                    for (int j = 0; j < 30; j++)
                    {

                        测试芯片 测试芯片 = new 测试芯片()
                        {
                            double功率 = 0,
                            double温度 = 0                      
                        };
                        CD测试芯片.TryAdd(j, 测试芯片);
                    }

                    测试单元格 测试单元格 = new 测试单元格()
                    {
                        物料编码 = "N/A",
                        产品批号 = "N/A",
                        故障代码 = 0,
                        通道号 = i + 1,
                        通道状态 = 4,
                        开始时间 = "N/A",
                        结束时间 = "N/A",
                        是否被选中 = false,
                        单元报警温度 = 999,
                        DT发送时间=DateTime.Now,
                        DT收到时间=DateTime.Now,
                        //是否可用=false,
                        double电流 =0,
                        CD测试芯片= CD测试芯片
                    };
                    CD测试单元格.TryAdd(i, 测试单元格);
                }
              
                CosBobject.物料编码 = ""; CosBobject.产品批号 = ""; CosBobject.产品型号 = "N/A"; CosBobject.单元报警温度 = "0"; CosBobject.水冷报警温度 = "0";
                CosBobject.一阶段电流 = "0"; CosBobject.一阶段时间 = "0"; CosBobject.二阶段电流 = "0"; CosBobject.二阶段时间 = "0"; CosBobject.三阶段电流 = "0"; CosBobject.三阶段时间 = "0";
                CosBobject.脉冲老化电流 = "0"; CosBobject.脉冲老化时间 = "0"; CosBobject.频率 = "0"; CosBobject.占空比 = "0"; CosBobject.结束时间 = "N/A"; CosBobject.选通通道号 = 0;
                CosBobject.CD测试单元格 = CD测试单元格; CosBobject.通道起 = 0; CosBobject.通道止 = 0;

            }
            catch (Exception ex)
            {
                NLOGex(ex);
            }
        }
        public static void ReadingComboBox()
        {
            try
            {
                PublicClass.Readfile(filePathComboBox, out PublicClass.ComboBoxIBook);
                myDataTable2 = PublicClass.ReadQueryTable(true, PublicClass.ComboBoxIBook);
                DataRow[]  myDataRow2 = myDataTable2.Select();

                for (int i = 0; i < myDataRow2.Count(); i++)
                {

                    ComboBoxBinding DataRow2 = new ComboBoxBinding()
                    {
                        Local_ID = Convert.ToInt32(myDataRow2[i]["ID"]),
                        测试项 = Convert.ToString(myDataRow2[i]["测试项"]).Trim(),
                        功率百分比 = Convert.ToInt32(myDataRow2[i]["功率百分比"]),
                        调制频率 = Convert.ToInt32(myDataRow2[i]["调制频率"]),
                        频率单位 = Convert.ToString(myDataRow2[i]["频率单位"]).Trim(),
                        调制频率上限 = Convert.ToInt32(myDataRow2[i]["调制频率上限"]),
                        调制频率下限 = Convert.ToInt32(myDataRow2[i]["调制频率下限"]),
                        占空比 = Convert.ToInt32(myDataRow2[i]["占空比"]),
                        测试时间 = Convert.ToInt32(myDataRow2[i]["测试时间"]),
                        测试单位 = Convert.ToString(myDataRow2[i]["测试单位"]).Trim(),
                        测试时间上限 = Convert.ToInt32(myDataRow2[i]["测试时间上限"]),
                        测试时间下限 = Convert.ToInt32(myDataRow2[i]["测试时间下限"]),
                    };
                    CDComboBox.TryAdd(i, DataRow2);
                }
            }
            catch (Exception ex)
            {
                NLOGex(ex);
            }
        }
        public static void NLOGex(Exception ex)
        {
            System.Diagnostics.StackTrace SS = new System.Diagnostics.StackTrace(true);
            System.Reflection.MethodBase MB = SS.GetFrame(1).GetMethod();
            string[] stringSeparators = new string[] { "line","行号" };
            string[] yunArray = ex.StackTrace.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
            string 方法名 = MB.Name;
            string 类名 = MB.DeclaringType.FullName;
            string 空间名 = MB.DeclaringType.Namespace;
            PublicClass.Logger.Error(类名 + "." + 方法名 + yunArray[1] + "行");
            PublicClass.Logger.Error(ex.Message);
        }
        public static void TraceMethodInfo(string message)
        {
            // 注意：StackTrace的参数1非常重要，表示获得父一级函数调用的相关信息。
            // 如果修改为0，则返回本身的行列信息，即TraceMethodInfo()函数的信息。
            StackFrame st = new System.Diagnostics.StackTrace(1, true).GetFrame(0);
            //string info = string.Format("{0}->{1}_{2}@{3}:{4}",
            //    st.GetFileName(),                       // 文件名
            //    st.GetMethod().DeclaringType.FullName,  // 类全名
            //    st.GetMethod().Name,                    // 方法名
            //    st.GetFileLineNumber(),                 // 所在行号
            //    st.GetFileColumnNumber());              // 所有列号

            string 文件名 = st.GetFileName();
            string 类全名 = st.GetMethod().DeclaringType.FullName;
            string 方法名 = st.GetMethod().Name;
            string 行号 = st.GetFileLineNumber().ToString();
            string 列号 = st.GetFileColumnNumber().ToString();
            PublicClass.Logger.Info(message);
            //PublicClass.Logger.Info("类：" + 类全名 + "方法：" + 方法名 + "行：" + 行号 + "列：" + 列号);
            //return info;
        }
        public static void tb_PreviewTextInput1(System.Windows.Controls.TextBox sender, TextCompositionEventArgs e)
        {
            //只能输入整数
            //System.Windows.Controls.TextBox TextBox_Text = sender;
            //Regex re1 = new Regex("[^0-9.-]+");
            //Regex re2 = new Regex("[^0-9.]+");
            //Regex re3 = new Regex("[^0-9-]+");
            //Regex re4 = new Regex("[^0-9]+");
            //string SearchString = sender.Text;
            //string SearchChar1 = "-";
            //string SearchChar2 = ".";
            //int TestPos1 = 0;
            //int TestPos2 = 0;

            //TestPos1 = SearchString.IndexOf(SearchChar1);
            //TestPos2 = SearchString.IndexOf(SearchChar2);

            //if (SearchString.Length == 0)
            //{
            //    e.Handled = re3.IsMatch(e.Text);
            //}
            //else
            //{
            //    if ((TestPos2 == 0) & (re4.IsMatch(Mid(SearchString, 2))))
            //    {
            //        e.Handled = re2.IsMatch(e.Text);
            //    }

            //    else
            //    {
            //        e.Handled = re4.IsMatch(e.Text);
            //    }
            //}

            string regexString = @"(^[0-9]*[1-9][0-9]*$)|(^([0-9]{1,})$)";//写正则表达式，只能输入数字
            e.Handled = !Regex.IsMatch(sender.Text + e.Text, regexString);
        }
        public static void tb_PreviewTextInput2(System.Windows.Controls.TextBox sender, TextCompositionEventArgs e)
        {
            string regexString = @"(^[0-9]*[0-9][0-9]*$)|(^([0-9]{1,}[.][0-9]*)$)";//写正则表达式，只能输入数字&小数
            e.Handled = !Regex.IsMatch(sender.Text + e.Text, regexString);
           
        }
        public static void tb_PreviewTextInput3(System.Windows.Controls.TextBox sender, TextCompositionEventArgs e)
        {
            Regex rgx = new Regex(@"^[-]?[0-9]*[.]?[0-9]*$");
            //rgx = new Regex(@"^(-?\d+)([.]\d+)?$");
            e.Handled = !rgx.IsMatch(sender.Text + e.Text);
        }
        public static string Mid(string param, int startIndex)
        {
            string result = param.Substring(startIndex - 1);
            return result;
        }
        public static void ReadData(string DataName, out string value, string IP)
        {
            DataRow[] DR = PublicClass.myDataTable4.Select("NameE = '" + DataName + "'");
            if (DR.Count() > 0)
            {
                int N = Convert.ToInt32(DR[0]["ID"]);
                //value = CDSDTstr[IP].CDUploadIntPA[N].strvalue;
                value = "0";
            }
            else
            {
                value = "N/A";
            }
        }
        public static void SetData(string DataName,  string value, string IP)
        {
            DataRow[] DR = PublicClass.myDataTable4.Select("NameC = '" + DataName + "'");
            if (DR.Count() > 0)
            {
                int N = Convert.ToInt32(DR[0]["ID"]);
                //CDSDTstr[IP].CDUploadIntPA[N].strvalue=value;
            }
        }
        public static class DispatcherHelper
        {
            [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
            public static void DoEvents()
            {
                DispatcherFrame frame = new DispatcherFrame();
                Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrames), frame);
                try { Dispatcher.PushFrame(frame); }
                catch (InvalidOperationException) { }
            }
            private static object ExitFrames(object frame)
            {
                ((DispatcherFrame)frame).Continue = false;
                return null;
            }
        }
        public static void Delay(int milliSecond)
        {
            int start = Environment.TickCount;
            while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
            {
                /*Application.DoEvents();*///可执行某无聊的操作
                DispatcherHelper.DoEvents();
            }
        }
        public static byte[] CS校验和(byte[] data)
        {
            // 假设 data 是要发送或接收的数据字节数组
            //byte[] data = { 0x01, 0x02, 0x03, 0x04, 0x05 };

            // 计算累加和校验和
            byte checksum = 0;
            for (int i = 0; i < data.Length; i++)
            {
                checksum += data[i];
            }
            // 将校验和添加到数据末尾
            byte[] packet = new byte[data.Length + 1];
            System.Array.Copy(data, packet, data.Length);
            packet[data.Length] = checksum;
            return packet;
        }
        public static byte[] byte数组合并(byte[] A, byte[] B)
        {
            A = A.Concat(B).Where(a => a > 0).ToArray();
            return A;
        }
    }
    public partial class App : Application
    {
        //public static Dictionary<string, object> Dic = new Dictionary<string, object>();
        protected override void OnStartup(StartupEventArgs e)
        {
            //Thread t = new Thread(() =>
            //{
            //    //Windows.SplashWindow sw = new Windows.SplashWindow();
            //    //Dic["SplashWindow"] = sw;//储存
            //    //sw.ShowDialog();//不能用Show
            //});
            //t.SetApartmentState(ApartmentState.MTA);//设置单线程
            //t.Start();
            //base.OnStartup(e);
        }      
    }
}
